package com.scrm.exam.config;


import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.math.BigDecimal;
import java.math.BigInteger;

@Configuration
public class JsonSerializerConfig {

    /**
     * Long类型转化为字符串返回给前端
     * <p>
     * 说明：
     */
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
        return builder -> {
            builder.serializerByType(Long.class, ToStringSerializer.instance)       // Long 转换为字符串
                    .serializerByType(Long.TYPE, ToStringSerializer.instance)        // long 转换为字符串
                    .serializerByType(BigInteger.class, ToStringSerializer.instance) // BigInteger 转换为字符串
                    .serializerByType(BigDecimal.class, ToStringSerializer.instance); // BigDecimal 转换为字符串
        };
    }

}